package com.example.homework7;

import android.content.Context;

import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;

@Database(entities = {User.class}, version = 1)
public abstract class MyRoomDataBase extends RoomDatabase {
    private static MyRoomDataBase instance;

    public abstract UserDao userDao();

    static MyRoomDataBase getInstance(Context context){
        if (instance == null){
            instance = Room.databaseBuilder(context.getApplicationContext(),
                    MyRoomDataBase.class,"room")
                    //这里为了测试，允许在主线程中使用room来
                    //但正是的应用不要这样用，数据库操作时会卡UI界面
                    //建议将数据库操作改成异步的
                    .allowMainThreadQueries()
                    .build();
        }
        return instance;
    }
}
